var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util")), e = getApp(), a = require("../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ a ],
    data: {
        faceServetitle: "serve-title",
        query: {
            title: "",
            recharge_member_mobile: "",
            recharge_merchant_mobile: "",
            recharge_total: 1,
            amount: "",
            points: 0
        },
        amount: "",
        setting: {},
        merchant_love_value: 0,
        checked: !1,
        flag: !1,
        isActive: !1,
        shopsActive: !1,
        errorText: "",
        ShopsErrorText: "",
        calculate: "",
        loveValue: 0
    },
    onLoad: function(t) {
        this.orderSetting();
    },
    orderSetting: function() {
        var t = this, a = e.getNetAddresss("plugin.face-to-face.frontend.recharge-order.set");
        e._getNetWork({
            url: a,
            data: {},
            success: function(e) {
                var a = e.data;
                if (1 == a.result) {
                    var o = a.data;
                    console.log(o), t.setData({
                        setting: o
                    }), "fixed" === o.merchant_love && t.setData({
                        merchant_love_value: o.merchant_love_value
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: t.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    multiplication: function(t) {
        var a = this, o = e.getNetAddresss("plugin.face-to-face.frontend.recharge-order.multiplication"), i = {
            data: t
        };
        e._postNetWork({
            url: o,
            data: i,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var o, i, r = e.data;
                    console.log(r), a.setData({
                        "query.amount": r
                    });
                    var n = [ a.data.setting.merchant_love_value, a.data.amount, null === (o = a.data.setting.integral_love_ratio) || void 0 === o ? void 0 : o.ratio ];
                    "ratio" === (null === (i = a.data.setting) || void 0 === i ? void 0 : i.merchant_love) && a.multiplicationLove(n);
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    multiplicationLove: function(t) {
        var a = this, o = e.getNetAddresss("plugin.face-to-face.frontend.recharge-order.multiplication"), i = {
            data: t
        };
        e._postNetWork({
            url: o,
            data: i,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var o = e.data;
                    a.setData({
                        merchant_love_value: o
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    monitorMoblie: function(t) {
        var e = t.detail;
        /^[1][3,4,5,6.7,8,9][0-9]{9}$/.test(e) ? (this.member(e, "consumer"), this.setData({
            isActive: !1
        })) : this.setData({
            isActive: !0,
            errorText: "请填写正确的手机号"
        });
    },
    merchantMoblie: function(t) {
        var e = t.detail;
        /^[1][3,4,5,6.7,8,9][0-9]{9}$/.test(e) ? (this.member(e, "shops"), this.setData({
            shopsActive: !1
        })) : this.setData({
            shopsActive: !0,
            ShopsErrorText: "请填写正确的手机号"
        });
    },
    changeprice: function(e) {
        var a = this;
        console.log(e);
        var o = e.detail;
        this.setData({
            amount: o.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
        });
        var i = [ this.data.amount, this.data.setting.pay_ratio ];
        this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
            t.default.debounce(a.multiplication(i));
        }, 500);
    },
    member: function(t, a) {
        var o = this, i = e.getNetAddresss("plugin.face-to-face.frontend.recharge-order.verify-member"), r = {
            mobile: t
        };
        e._postNetWork({
            url: i,
            data: r,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var i = e.data;
                    "consumer" === a ? o.setData({
                        "query.recharge_member_mobile": i.mobile,
                        errorText: ""
                    }) : o.setData({
                        "query.recharge_merchant_mobile": i.mobile,
                        ShopsErrorText: ""
                    });
                } else "consumer" === a ? o.setData({
                    isActive: !0,
                    errorText: e.msg
                }) : (console.log(e.msg), o.setData({
                    shopsActive: !0,
                    ShopsErrorText: e.msg
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    sellChange: function(t) {
        this.setData({
            checked: t.detail
        });
    },
    blurinput: function(t) {
        var e = t.detail;
        this.setData({
            "query.title": e
        });
    },
    totalOnChange: function(t) {
        this.setData({
            "query.recharge_total": t.detail
        });
    },
    orderPay: function() {
        var t = this;
        if (this.data.query.title) if (this.data.query.recharge_total) if (this.data.query.recharge_member_mobile) if (this.data.query.recharge_merchant_mobile) if (this.data.query.amount) if (this.data.isActive) wx.showToast({
            icon: "none",
            title: this.data.errorText,
            duration: 1500
        }); else if (this.data.shopsActive) wx.showToast({
            icon: "none",
            title: this.data.ShopsErrorText,
            duration: 1500
        }); else if (this.data.checked) {
            this.setData({
                flag: !0
            });
            var a = e.getNetAddresss("plugin.face-to-face.frontend.recharge-order.create"), o = this.data.query, i = this.data.amount, r = Number(i).toFixed(2) || "0.00";
            this.data.query.amount = this.data.query.amount.toString(), this.data.query.points = r.toString(), 
            e._getNetWork({
                url: a,
                data: o,
                success: function(e) {
                    var a = e.data;
                    if (1 == a.result) {
                        var o = {
                            order_ids: a.data.order_ids,
                            api: "plugin.face-to-face.frontend.recharge-order.index"
                        };
                        setTimeout(function() {
                            wx.navigateTo({
                                url: "/packageD/buy/orderPay/orderPay?order_id=".concat(o.order_ids, "&api=").concat(o.api)
                            }), t.setData({
                                flag: !1
                            });
                        }, 1e3);
                    } else setTimeout(function() {
                        t.setData({
                            flag: !1
                        });
                    }, 1e3), wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }), wx.hideLoading();
                },
                fail: function(t) {
                    var e = this;
                    setTimeout(function() {
                        e.setData({
                            flag: !1
                        });
                    }, 1e3);
                }
            });
        } else wx.showToast({
            icon: "none",
            title: "请勾选协议",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请输入金额",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请输入商家会员手机号",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请输入会员手机号",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请输入商品数量",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请输入商品名称或服务名称",
            duration: 1500
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});